package WinterFlower.work0715.exampleclass;

import java.util.Arrays;

/**
 * @author ZJM
 * @version 1.0
 * @since 2022-07-15 18:41:10
 */
public class StringConstructor {
    public static void main(String[] args) {
        byte [] bytes = {97,98,99,100,101,102};

        String s1 = new String(bytes);//按照默认字符编码集unicode 来转换字节整数的码值到字符
        System.out.println(s1);

        String s2 = new String(bytes, 1, 3);
        System.out.println(s2);

        char[] chars = {'A','我',66,'!','=','他'};
        System.out.println(new String(chars));
        String s3 = new String(chars,3,3);
        System.out.println(s3);


//    字符串到字节 字符数组
        String name = "夏日一个雪糕";//UTF-8下 一个汉字字节使用3个字节表示
        byte[] nameBytes = name.getBytes();
        System.out.println(Arrays.toString(nameBytes));

        char [] chars1 = name.toCharArray();
        System.out.println(Arrays.toString(chars1));

//    ---------------------------------------------------
        char c = name.charAt(3);//指定索引出的字节码 从0 开始
        System.out.println(c);

//    长度 字符个数
        System.out.println(name.length());

        for (int i = 0; i <name.length() ; i++) {
            System.out.println(i+"="+name.charAt(i));

        }

//    求字符串里面的大写字母个数
        String str = "fgiwefDSAUD";
        int count= 0;
        for (int i = 0; i <str.length() ; i++) {
            if(Character .isUpperCase(str.charAt(i)));{
                count ++;
            }
        }
        System.out.println(count);
    }
}
